package  plugins.lsd.SlidingPuzzle
{
	import core.manager.MainSystem;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import gs.TweenLite;
	
	import memory.MemoryRecovery;
	
	public class SlidingPuzzleGame extends Sprite
	{
		private var slidingPuzzle:SlidingPuzzle;
		private var url:Array=["point/img/19_1_1.jpg","point/img/19_1_2.jpg","point/img/19_1_3.jpg","point/img/19_1_4.jpg","point/img/19_1_5.jpg"]
	    private var i:int=0;
		
		public function SlidingPuzzleGame()
		{
			init();
		}
		
		private function init():void{
			MainSystem.getInstance().isBusy=true;
			slidingPuzzle=new SlidingPuzzle();
			addChild(slidingPuzzle);
			slidingPuzzle.loadBitmap(url[i]);
			slidingPuzzle.addEventListener(SlidingEvent.PUZZLE_CHANG,next_fun);
			slidingPuzzle.addEventListener(Event.COMPLETE,on_loaded);
		}
		
        private function on_loaded(e:Event):void
		{
			MainSystem.getInstance().isBusy=false;
		}
		private function next_fun(e:SlidingEvent):void{
			
			 if(url[i].toString()!="point/img/19-1-5.jpg")
			 {	
			 i++;
			 TweenLite.from(slidingPuzzle,1,{alpha:0});
			 
             

			 TweenLite.to(slidingPuzzle,1,{alpha:1,onStart: function():void{
			 	 
			 	 slidingPuzzle.clearPuzzle();
			 	 slidingPuzzle.loadBitmap(url[i]);
			
			 }});
			 }
			 else{
			 	
			 	dispatchEvent(new SlidingEvent(SlidingEvent.PUZZLE_END));
			 	
			 }
			 
		}
		private function dispose_sp():void{
			
			MainSystem.getInstance().runAPIDirectDirectly("removePluginById",["SlidingModule"]);
		}
		public function dispose():void{
			
			MemoryRecovery.getInstance().gcFun(slidingPuzzle,SlidingEvent.PUZZLE_CHANG,next_fun);
			MemoryRecovery.getInstance().gcFun(slidingPuzzle,Event.COMPLETE,on_loaded);
			MemoryRecovery.getInstance().gcObj(slidingPuzzle,false);
			
		}

	}
}